package jp.ac.waseda.info.ueda.unyo.panel;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import jp.ac.waseda.info.ueda.unyo.manager.NodePainter;

public class AnalysisPanel extends JPanel {
	
	///////////////////////////////////////////////////////////////////////////
	final static
	public String TITLE = "Analysis";
	final static
	public String INTERSECTIONS = "crossing : ";
	final static
	public String CALC = "Calculating...";
	final static
	public String DENSITY = "Dencity of nodes :";
	final static
	public String COUNT_CROSSING = "Count crossing links";
	final static
	public String STOP = "Stop";
	
	static
	private JButton intersectionNumBt_;
	static
	private JLabel intersectionNumLabel_;
//	static
//	private JTextField intersectionNumLabel_;
	
	static
	private JPanel p1_;
	
	///////////////////////////////////////////////////////////////////////////
	
	public AnalysisPanel(){
		intersectionNumBt_ = new JButton(COUNT_CROSSING);
		intersectionNumBt_.addActionListener(new InterSectionActionListener());
		intersectionNumBt_.setFocusable(false);
		
		intersectionNumLabel_ = new JLabel(INTERSECTIONS);
//		intersectionNumLabel_ = new JTextField(INTERSECTIONS);
//		intersectionNumLabel_.setPreferredSize(new Dimension(500, 100));
		
		p1_ = new JPanel();
		p1_.setLayout(new FlowLayout());
		setLayout(new BorderLayout());
		
		p1_.add(intersectionNumLabel_);
		p1_.add(intersectionNumBt_);
//		p1_.add(densityBt_);
//		p1_.add(densityLabel_);
//		scroll_ = new JScrollPane(p1_);
//		add(scroll_, BorderLayout.CENTER);
		add(p1_, BorderLayout.CENTER);
	}
	
	///////////////////////////////////////////////////////////////////////////

	static
	public void setIntersection(String size){
		intersectionNumLabel_.setText(INTERSECTIONS + size);
	}
		
	private class InterSectionActionListener implements ActionListener{
		public InterSectionActionListener(){
		}
		public void actionPerformed(ActionEvent e) {
			if(intersectionNumBt_.getText().equals(COUNT_CROSSING)){
				NodePainter.countIntersection_ = true;
				intersectionNumLabel_.setText(CALC);
				intersectionNumBt_.setText(STOP);
			}else{
				NodePainter.countIntersection_ = false;
				intersectionNumLabel_.setText(INTERSECTIONS);
				intersectionNumBt_.setText(COUNT_CROSSING);
			}
		}
	}
	
}